import { getSecondHouseList } from "@/api/bizSecondHouse";
import { Image, ScrollView, Text, View } from "@tarojs/components";
import { useLoad, usePullDownRefresh } from "@tarojs/taro";
import { useState } from "react";
import { connect } from "react-redux";
import right from "@/assets/right.png";
import BackTitle from "@/components/BackTitle";
import "./index.scss";
import { navigateTo } from "@/utils/common";

function SecondHouseList(props) {
    const [caseList, setCaseList] = useState([]);
    const { cardNo } = props;
    const loadData = () => {
        getSecondHouseList({ cardNo }).then((res) => {
            setCaseList(res);
        });
    };

    useLoad(loadData);
    usePullDownRefresh(loadData);

    const onCaseClick = (info) => {
        navigateTo("pages/subs/secondHouseDetail");
    };

    const caseListView = caseList.map((info: any, index) => {
        return (
            <View
                className="scroll_item"
                onClick={() => this.onCaseClick(info)}
                key={index}
            >
                <View className="scroll_item_text">
                    <Text>编号：{info.bh}</Text>
                    <Text>坐落：{info.zl}</Text>
                    <Text>出售人：{info.csr}</Text>
                    <Text>买受人：{info.msr}</Text>
                    <Text>申请状态：{info.sqzt}</Text>
                </View>
                <Image src={right} className="scroll_item_img"></Image>
            </View>
        );
    });

    return (
        <View>
            <BackTitle title="转移登记" />
            <ScrollView scrollY scrollWithAnimation>
                {caseList.length > 0 ? caseListView : "暂无数据"}
            </ScrollView>
        </View>
    );
}

export default connect(
    ({ user }: any) => {
        const { cardNo } = user;
        return { cardNo };
    },
    null,
    null,
    { forwardRef: true }
)(SecondHouseList);
